'use strict';

const getCategories = require('./get-categories');
const addCategory = require('./add-category');
const updateCategory = require('./update-category');
const deleteCategory = require('./delete-category');
const batchOperate = require('./batch-operate');
const getStatistics = require('./get-statistics');
const getCategoryDetail = require('./get-category-detail');

exports.main = async (event, context) => {
  const { action, data } = event;
  
  try {
    switch (action) {
      case 'get-categories':
        return await getCategories.main(event, context);
      case 'add-category':
        return await addCategory.main(event, context);
      case 'update-category':
        return await updateCategory.main(event, context);
      case 'delete-category':
        return await deleteCategory.main(event, context);
      case 'batch-operate':
        return await batchOperate.main(event, context);
      case 'get-statistics':
        return await getStatistics.main(event, context);
      case 'get-category-detail':
        return await getCategoryDetail.main(event, context);
      default:
        return {
          code: 400,
          message: '未知的操作类型',
          data: null
        };
    }
  } catch (error) {
    console.error('云函数执行错误:', error);
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};